package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao {

    private static Teacher[] teachers = new Teacher[5];

    public boolean addTeacher(Teacher tea) {

        int index = -1;
        for (int i = 0; i < teachers.length; i++) {

            if (teachers[i] == null) {
                index = i;
                break;

            }
        }
        if (index == -1) {
            return false;
        } else {
            teachers[index] = tea;
            return true;
        }
    }

    public Teacher[] getAllTeacher() {
        return teachers;

    }

    public void delTeacher(String id) {

        int index = getIndex(id);
        teachers[index] = null;

    }

    public int getIndex(String id) {

        int index = -1;

        for (int i = 0; i < teachers.length; i++) {

            if (teachers[i] != null && id.equals(teachers[i].getId())) {
                index = i;
            }
        }
        return index;
    }

    public void changeTeacher(String id, Teacher tea) {

        int index = getIndex(id);
        teachers[index] = tea;

    }
}
